﻿using System;
using System.Collections.Generic;

namespace dPet.Domain.Models
{
	using Hangerd.Entity;

	/// <summary>
	/// 入库批次
	/// </summary>
	public class InventoryBatch : EntityBase
	{
		#region Public Properties

		/// <summary>
		/// 批次号
		/// </summary>
		[RecordModify]
		public string BatchNumber { get; private set; }

		/// <summary>
		/// 所属医院ID
		/// </summary>
		public string HospitalId { get; private set; }

		/// <summary>
		/// 入库明细
		/// </summary>
		public virtual ICollection<InventoryBatchDetail> Details { get; private set; }

		/// <summary>
		/// 操作人
		/// </summary>
		[RecordModify]
		public string Operator { get; private set; }

		/// <summary>
		/// 入库时间
		/// </summary>
		public DateTime CreateTime { get; private set; }

		#endregion

		#region Constructors

		private InventoryBatch() { }

		public InventoryBatch(Hospital hospital, string @operator)
		{
			this.BatchNumber = string.Format("IB-{0}-{1}", hospital.Id.Substring(0, 6).ToUpper(), DateTime.Now.ToString("yyyyMMddHHmmss"));
			this.HospitalId = hospital.Id;
			this.Details = new List<InventoryBatchDetail>();
			this.Operator = @operator;
			this.CreateTime = DateTime.Now;
		}

		#endregion

		#region Public Methods

		/// <summary>
		/// 增加入库明细
		/// </summary>
		public void AddDetail(string productId, int quantity, DateTime expiryTime)
		{
			this.Details.Add(new InventoryBatchDetail(productId, quantity, expiryTime));
		}

		#endregion
	}
}
